package cn.zf233.xcloud.web.socket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnOpen;
import javax.websocket.Session;

/**
 * Created by zf233 on 2021/8/6
 * WebSocket 抽象类
 */
public abstract class BaseSocket {

    private final Logger logger = LoggerFactory.getLogger(FlowChartSocket.class);

    public abstract void sendMessage(Session session);

    // 建立连接成功调用
    @OnOpen
    public void onOpen(Session session) {
        logger.info("链接建立成功");
        sendMessage(session);
    }

    // 关闭连接时调用
    @OnClose
    public void onClose() {
        logger.info("链接关闭");
    }

    // 错误时调用
    @OnError
    public void onError(Throwable throwable) {
        logger.error("发生错误 {}", throwable.getMessage());
    }
}
